package com.zjsru.oneDay202203;

/**
 * @Author: likew
 * @Date: 2022/3/7
 *
 * <p>
 * 七进制数
 * <p>
 * 输入: num = 100 输出: "202" 输入: num = -7 输出: "-10"
 */
public class convertToBase7 {
    
    public String convertToBase7(int n) {
        boolean flag = n < 0;
        if (flag) {
            n = -n;
        }
        StringBuilder sb = new StringBuilder();
        do {
            sb.append(n % 7);
            n = n / 7;
        } while (n != 0);
        sb.reverse();
        return flag ? "-" + sb.toString() : sb.toString();
    }
    
//    /* leetcode 方法 Integer.toString(int par1,int par2),par1表示要转成字符串的数字，par2表示要转成的进制表示，*/
//    public String convertToBase7(int n) {
//        return Integer.toString(n, 7);
//    }

    public static void main(String[] args) {
        convertToBase7 convertToBase7 = new convertToBase7();
        int n = -7;
        System.out.println(convertToBase7.convertToBase7(n));
    }
}
